﻿using System.Collections.Generic;
using System.Linq;
using Thinker.SignChannel.Entities;
using Volo.Abp.DependencyInjection;

namespace Thinker.SignChannel.Results;

public class OutResultCalculator : ResultCalculator, ITransientDependency
{
    public SignResult Calc(IEnumerable<Record> records, Time time)
    {
        var activeRecord = GetActiveRecord(records);
        return Calc(time, activeRecord);
    }

    public Record GetActiveRecord(IEnumerable<Record> records)
    {
        return records.MaxBy(x => x.RecordTime)!;
    }

    public SignResult Calc(Time time, Record activeRecord)
    {
        if (activeRecord.RecordTime < time.SignTime)
        {
            return SignResult.OutEarly;
        }

        return SignResult.Normal;
    }
}